﻿namespace WebPacker.Tests.Configuration
{
	using System.Collections.Generic;
	using NUnit.Framework;
	using WebPacker.Configuration;

	public class PackInfoEqualityComparer : IEqualityComparer<PackInfo>
	{
		public bool Equals(PackInfo x, PackInfo y)
		{
			if (x == y)
			{
				return true;
			}

			if (x.Name == y.Name)
			{
				Assert.AreEqual(x.BasePath, y.BasePath);
				Assert.AreEqual(x.FilterName, y.FilterName);
				Assert.AreEqual(x.Monitoring, y.Monitoring);
				Assert.AreEqual(x.PackType, y.PackType);
				Assert.AreEqual(x.Version, y.Version);
				Assert.AreEqual(x.VersionGeneratorName, y.VersionGeneratorName);

				if (x.Resources != null)
				{
					Assert.IsNotNull(y.Resources);
					Assert.AreEqual(x.Resources.Length, y.Resources.Length);

					for (var i = 0; i < x.Resources.Length; i++)
					{
						var xres = x.Resources[i];
						var yres = y.Resources[i];

						Assert.IsNotNull(xres);
						Assert.IsNotNull(yres);
						Assert.AreEqual(xres.Name, yres.Name);
						Assert.AreEqual(xres.Encoding, yres.Encoding);
					}
				}
				else
				{
					Assert.IsNull(y.Resources);
				}

				return true;
			}

			return false;
		}

		public int GetHashCode(PackInfo obj)
		{
			return obj.GetHashCode();
		}
	}
}
